{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.ensemble import VotingClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "c1 = pd.read_csv('pred_89129_61618',header=None,names=['CUST_NO','Label'])\n",
    "c2 = pd.read_csv('pred_89479_61914',header=None,names=['CUST_NO','Label'])\n",
    "c3 = pd.read_csv('pred_89323_61785',header=None,names=['CUST_NO','Label'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "c = c1.merge(c2,on='CUST_NO').merge(c3,on='CUST_NO')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CUST_NO</th>\n",
       "      <th>Label_x</th>\n",
       "      <th>Label_y</th>\n",
       "      <th>Label</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2ea465c039dca553869709c9f07d3e98</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>805a1b20b7655ae02ecb2b1a216df747</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>f8c8c42606afa6e1ab4247c9d9903e79</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>8e63b90522f7d0f89930c141b6d62ba3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>e71614849f7148cd0d1876b58cf23f5b</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5019</th>\n",
       "      <td>7076d61327935a1f72299b2a071eed45</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5020</th>\n",
       "      <td>6c57011bf118ee499d9fd25ae831ec5f</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5021</th>\n",
       "      <td>9ca1d27116d16ea35e5e8084f696aec0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5022</th>\n",
       "      <td>3898fe5dcf8ca288f09491f357c25a9d</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5023</th>\n",
       "      <td>94e9acd2695baa4500674d09a6a54708</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5024 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                               CUST_NO  Label_x  Label_y  Label\n",
       "0     2ea465c039dca553869709c9f07d3e98        0        0      0\n",
       "1     805a1b20b7655ae02ecb2b1a216df747        1        1      1\n",
       "2     f8c8c42606afa6e1ab4247c9d9903e79        0        0      0\n",
       "3     8e63b90522f7d0f89930c141b6d62ba3        0        0      0\n",
       "4     e71614849f7148cd0d1876b58cf23f5b        0        0      0\n",
       "...                                ...      ...      ...    ...\n",
       "5019  7076d61327935a1f72299b2a071eed45        0        0      0\n",
       "5020  6c57011bf118ee499d9fd25ae831ec5f        0        0      0\n",
       "5021  9ca1d27116d16ea35e5e8084f696aec0        0        0      0\n",
       "5022  3898fe5dcf8ca288f09491f357c25a9d        0        0      0\n",
       "5023  94e9acd2695baa4500674d09a6a54708        0        0      0\n",
       "\n",
       "[5024 rows x 4 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5024, 4)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "c['sum'] = c.iloc[:,1:].sum(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "CUST_NO    626\n",
       "Label_x    626\n",
       "Label_y    626\n",
       "Label      626\n",
       "sum        626\n",
       "dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c[c['sum']>=2].count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "c['Vote'] = [1 if x >=2 else 0 for x in c['sum']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "c[['CUST_NO','Vote']].to_csv('B榜结果.csv',index=False,header=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2ea465c039dca553869709c9f07d3e98,0\n",
      "805a1b20b7655ae02ecb2b1a216df747,1\n",
      "f8c8c42606afa6e1ab4247c9d9903e79,0\n",
      "8e63b90522f7d0f89930c141b6d62ba3,0\n",
      "e71614849f7148cd0d1876b58cf23f5b,0\n",
      "b3dc8721ff073ba060adc482db54954a,0\n",
      "4d426452a6713fd96e86dd1f840f816b,0\n",
      "0f7b61dcd9e7aa108aaa852f4a0c7525,0\n",
      "ddea93dde6f9eac2123ac09747763b27,0\n",
      "d101c2a918090b96618b6d529ed75337,0\n"
     ]
    }
   ],
   "source": [
    "!head B榜结果.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  5024   5024 175840 B榜结果.csv\n"
     ]
    }
   ],
   "source": [
    "!wc B榜结果.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    4398\n",
       "1     626\n",
       "Name: Vote, dtype: int64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c['Vote'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1_数据读取_B榜\t\t  5_模型融合_B榜_vote.ipynb  pred_89323_61785\n",
      "2_模型训练_B榜_lgb.ipynb  B榜结果.csv\t\t     pred_89479_61914\n",
      "3_模型训练_B榜_cbt.ipynb  fea\t\t\t     test.csv\n",
      "4_模型训练_B榜_xgb.ipynb  pred_89129_61618\t     train.csv\n"
     ]
    }
   ],
   "source": [
    "!ls "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Database connected, autolimit set to 500.\n",
      "Matplotlib env init complete.\n",
      "Warnings off.\n"
     ]
    }
   ],
   "source": [
    "init_woody"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'请稍后使用命令: %query_predict problem_id 查看评分结果, problem_id为阶段序号，取值为：1,2, 比如查询第一阶段的评分结果: %query_predict 1'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%predict 4 B榜结果.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "最近三次评分提交的结果(供参考):\n",
      "\n",
      "提交时间：2022-10-31 17:39:09 \t 评分结果：0.608487   \t 评分成功\n",
      "提交时间：2022-10-27 10:48:04 \t 评分结果：0.608487   \t 评分成功\n",
      "提交时间：2022-10-27 10:46:26 \t 评分结果：0.608487   \t 评分成功\n"
     ]
    }
   ],
   "source": [
    "%query_predict 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
